#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, k;
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int sz[N];
bool dfs(int u, int fu) {
  sz[u] = 1;
  vector<int> ch;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    if (!dfs(v, u)) return false;
    if (sz[v]) ch.push_back(sz[v]);
  }
  if (ch.size() == 1) {
    sz[u] += ch[0];
  } else if (ch.size() == 2) {
    sz[u] += ch[0] + ch[1];
    if (sz[u] != k) return false;
  } else if (ch.size() > 0) {
    return false;
  }
  sz[u] %= k;  // taking cares if k == 1
  return true;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  n *= k;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  if (dfs(1, 0) && sz[1] % k == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}